package com.zhao.controller;


import com.zhao.Result;
import com.zhao.entity.EduChapter;
import com.zhao.entity.chapter.Chapter;
import com.zhao.service.EduChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author xiaozhao
 * @since 2021-07-26
 */
@RestController
@RequestMapping("eduservice/chapter")
@CrossOrigin
public class EduChapterController {

    @Autowired
    private EduChapterService chapterService;
    //根据课程id树形获取章节和小节信息
    @GetMapping("/getTree/{courseId}")
    public Result getTree(@PathVariable String courseId){
       List<Chapter>list= chapterService.getChapterAndVideo(courseId);
       return Result.ok().data("list",list);
    }
    //添加章节的基本信息
    @PostMapping("/addChapter")
    public Result addChapter(@RequestBody EduChapter chapter){
        String id=chapterService.saveChapter(chapter);
        return Result.ok().data("id",id);
    }
    //编辑章节信息
    @PostMapping("/updateChapter")
    public Result updateChapter(@RequestBody EduChapter chapter){
        String id=chapterService.updateChapter(chapter);
        return Result.ok().data("id",id);
    }
    //根据章节id查询章节信息
    @GetMapping("/findChapterById/{id}")
    public Result findChapterById(@PathVariable String id){
        EduChapter chapter = chapterService.getById(id);
        return Result.ok().data("chapter",chapter);
    }
    //根据章节id删除章节信息
    @PostMapping("/deleteChapterInfo/{id}")
    public Result deleteChapterInfo(@PathVariable String id){
        chapterService.deletechapter(id);
        return Result.ok();
    }
}

